package chapter2.No2_2_synchronized同步语句块.i静态同步方法与synchronized_class代码块.demo4;

/**
 * Created by Administrator on 2016/11/12.
 */
public class ServiceClass {
    public static void methodA() {
        synchronized (ServiceClass.class){
            try {
                System.out.println("线程：" + Thread.currentThread().getName() + " 进入静态同步方法A");
                Thread.sleep(500);
                System.out.println("线程：" + Thread.currentThread().getName() + " 退出静态同步方法A");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void methodB() {
        synchronized (ServiceClass.class){
            try {
                System.out.println("线程：" + Thread.currentThread().getName() + " 进入静态同步方法B");
                Thread.sleep(500);
                System.out.println("线程：" + Thread.currentThread().getName() + " 退出静态同步方法B");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
